package android.slc.extras.component.dict.entity;

import com.blankj.utilcode.util.CollectionUtils;
import com.blankj.utilcode.util.StringUtils;

import java.util.List;

/**
 * @Description:
 * @Author: sunlunchang
 * @CreateDate: 2021/12/13 下午 2:48
 */
public class TreeDictWrap {
    private List<? extends ITreeDict<?>> sysDictList;
    private String[] dictLabelArray;

    public TreeDictWrap() {

    }

    public TreeDictWrap(List<? extends ITreeDict<?>> sysDictList) {
        setSysDictList(sysDictList);
    }

    public List<? extends ITreeDict<?>> getSysDictList() {
        return sysDictList;
    }

    public void setSysDictList(List<? extends ITreeDict<?>> sysDictList) {
        this.sysDictList = sysDictList;
        dictLabelArray = dictList2LabelArray(sysDictList);
    }

    public String[] getDictLabelArray() {
        return dictLabelArray;
    }

    public void setDictLabelArray(String[] dictLabelArray) {
        this.dictLabelArray = dictLabelArray;
    }

    public static <T extends ITreeDict<?>> String[] dictList2LabelArray(List<T> dictList) {
        if (CollectionUtils.isEmpty(dictList)) {
            return new String[0];
        }
        final String[] labelArray = new String[dictList.size()];
        CollectionUtils.forAllDo(dictList, (index, item) -> labelArray[index] = StringUtils.isEmpty(item.getTdDictLabel()) ? " " : item.getTdDictLabel());
        return labelArray;
    }
}
